package com.qf.test;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

public class Demo1 {


    @Test
    public void test() throws IOException {
        //1. 加载mybatis-config文件
        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");

        //2. 构建SqlSessionFactory工厂对象
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(inputStream);

        //3. 构建SqlSession
        SqlSession sqlSession = factory.openSession();

        //4. 通过SqlSession执行SQL语句并获取返回结果
        Long count = sqlSession.selectOne("user.selectCount");

        //5. 输出
        System.out.println(count);
    }

}
